#include "StdAfx.h"
#include "LogicThread.h"


LogicThread::LogicThread(void)
{
}


LogicThread::~LogicThread(void)
{
}

DWORD LogicThread::ResumeThread()
{
    return ::ResumeThread(m_hThread);
}

void LogicThread::InitThread()
{
    m_hThread=(HANDLE)_beginthreadex(NULL,0,(PTHREAD_START)ThreadProc,this,CREATE_SUSPENDED,NULL);
}

DWORD WINAPI LogicThread::ThreadProc( PVOID pvParam )
{
    LogicThread* thread=static_cast<LogicThread*> (pvParam);

    thread->Run();

    return 0;
}

HANDLE LogicThread::GetHandle()
{
    return m_hThread;
}

void LogicThread::Run()
{
    while (true)
    {
        TaskItem* item=NULL;

        item=m_queueTask.PopItem();

        if (NULL==item)
        {
            break;
        }
        item->task_->Run();
        item->Release();
    }
}


void LogicThread::PushTask( ITask* pTask )
{
    if (pTask==NULL)
    {
        return;
    }
    TaskItem* pItem = new TaskItem( pTask );
    m_queueTask.PushItem( pItem );
}